package com.hengxinguotong.zhihuichengjian.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.hengxinguotong.zhihuichengjian.R;
import com.hengxinguotong.zhihuichengjian.bean.Material;
import com.hengxinguotong.zhihuichengjian.widget.font.HXTextView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by liux on 2017/3/7.
 */

public class MaterialUseListAdapter extends BaseAdapter {
    private List<Material> datas;
    private Context context;

    public MaterialUseListAdapter(List<Material> datas, Context context) {
        this.context = context;
        this.datas = datas;
    }

    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public Object getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null || convertView.getTag() == null) {
            convertView = LayoutInflater.from(context)
                    .inflate(R.layout.item_material_uselist, parent, false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        Material material = datas.get(position);
        holder.name.setText(material.getName());
        holder.number.setText(material.getQuantity() + material.getUnit());
        holder.user.setText(material.getUsePerson());
        holder.standard.setText(material.getModel());
        holder.registerDate.setText(material.getCreateTime()+"  "+material.getCreateBy());
//        holder.useDate.setText(material.getRecipientsDate());
//        if (material.getStatus()==1) {
//            holder.state.setImageResource(R.mipmap.pending_confirmation);
//            holder.stateTv.setText("待确认");
//            holder.stateTv.setTextColor(context.getResources().getColor(R.color.color_1294db));
//        } else if (material.getStatus()==4) {
//            holder.state.setImageResource(R.mipmap.already_confirmed);
//            holder.stateTv.setText("已确认");
//            holder.stateTv.setTextColor(context.getResources().getColor(R.color.color_71e5a2));
//        } else {
//            holder.state.setImageResource(R.mipmap.canceled);
//            holder.stateTv.setText("驳回取消");
//            holder.stateTv.setTextColor(context.getResources().getColor(R.color.color_f1636a));
//        }
        return convertView;
    }

    static class ViewHolder {
        @BindView(R.id.name)
        HXTextView name;
        @BindView(R.id.number)
        HXTextView number;
        @BindView(R.id.user)
        HXTextView user;
        @BindView(R.id.standard)
        HXTextView standard;
        @BindView(R.id.register_date)
        HXTextView registerDate;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
